// 导入axios对象
import axios from "axios"

axios.defaults.baseURL = "https://www.liulongbin.top:8888/api/private/v1/"
// 配置请求拦截器
axios.interceptors.request.use(function (config) {
    let token = sessionStorage.getItem("token")
    config.headers['Authorization'] = token
    return config

}, function (error) {
    return Promise.reject(error)
})
// 响应拦截器
axios.interceptors.response.use((response) => {

    // if (response.status == 200) {
    //     return response.data
    // }
    return response

}, (error) => {
    return Promise.reject(error)
})

let Request = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            ...params
        }).then((res) => {
            resolve(res)
        }).catch((err) => {
            reject(err)
            
        })
    })
}

// 抛出拦截器
export default Request